from pprint import pprint

classes = [
    {"name": "n_1", "age": 24, "grade": "A"},
    {"name": "n_2", "age": 23, "grade": "B"},
    {"name": "n_3", "age": 28, "grade": "A"},
    {"name": "n_4", "age": 24, "grade": "A"},
    {"name": "n_5", "age": 25, "grade": "C"},
    {"name": "n_6", "age": 21, "grade": "D"},
    {"name": "n_7", "age": 27, "grade": "A"},
]


# sort list by grade
def sort_by_grade(ori_list):
    copy_list = ori_list.copy()
    return sorted(copy_list, key=lambda k: k['grade'])


# function of filter grade equals to A
def filter_grade(ori_list):
    copy_list = ori_list.copy()
    filter_result = filter(lambda k: k['grade'] == 'A', copy_list)
    return list(filter_result)


# use map to increase age
def increase_age_use(ori_list, increase=1):
    copy_list = ori_list.copy()
    map_result = list(map(lambda v: v['age'] + increase, copy_list))
    for i in range(len(copy_list)):
        copy_list[i]['age'] = map_result[i]
    return copy_list


pprint(classes)
print(sort_by_grade(classes))
print(filter_grade(classes))
print(increase_age_use(classes, 1))